package view.controller;

import common.Communication;
import common.Message;
import common.NowUser;
import common.User;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.event.ActionEvent;
import javafx.fxml.Initializable;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.ScrollPane;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.FlowPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Priority;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.scene.shape.Circle;
import javafx.scene.shape.Polygon;
import javafx.stage.Stage;
import server.ClientConnServer;
import tools.GetTime;

import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ResourceBundle;
import java.util.concurrent.BrokenBarrierException;

public class EmojiController implements Initializable {
    public Label friendid;
    public Button h0;
    public Button h1;
    public Button h2;
    public Button h3;
    public Button h4;
    public Button h5;
    public Button h6;
    public Button h7;
    public Button h8;
    public Button h9;
    public Button h10;
    public Button h11;
    public Button h12;
    public Button h13;
    public Button h14;
    public Button h15;
    public Button h16;
    public Button h17;
    public Button h18;
    public Button h19;
    public Button h20;
    public Button h21;
    public Button h22;
    public Button h23;
    public boolean last = true;

    @Override
    public void initialize(URL location, ResourceBundle resources) {
        friendid.setText(NowUser.friend.getId());
    }

    public void on0(ActionEvent actionEvent) throws IOException, BrokenBarrierException, InterruptedException {
        Message msg = new Message();
        Communication comm  = new Communication();
        comm.setSender(NowUser.user);
        User friend=new User();
        friend.setId(friendid.getText());
        Message getusermsg=new Message();
        getusermsg.setType("getfriend");
        getusermsg.setUser(friend);
        new ClientConnServer().sendinfo(getusermsg);
        NowUser.cyclicBarrier.reset();
        NowUser.cyclicBarrier.await();
        friend=NowUser.friend;
        comm.setReceiver(friend);
        comm.setContent(h0.getText());
        comm.setSendDateTime(new GetTime().getTime());
        comm.setType(4);
        System.out.println(comm.getSender().getId()+"，"+comm.getReceiver().getId()+","+comm.getContent());
        msg.setType("emoji");
        msg.setCommunication(comm);
        new ClientConnServer().sendinfo(msg);
        NowUser.cyclicBarrier.reset();
        NowUser.cyclicBarrier.await();
        FlowPane flowPane=ManageChat.getMeesagelist(NowUser.user.getId()+msg.getCommunication().getReceiver().getId());
        ScrollPane scrollPane=ManageChat.getScrollPaneHashMap(NowUser.user.getId()+msg.getCommunication().getReceiver().getId());
        // System.out.println(flowPane+"flow");
        VBox.setVgrow(flowPane, Priority.ALWAYS);
        URL url = null;
        try {
            if (msg.getCommunication().getSender().getHeadimage() == null || msg.getCommunication().getSender().getHeadimage().equals("") || msg.getCommunication().getSender().getHeadimage().equals("null")) {
                url = new URL("file:E:untitled\\src\\view\\photo\\默认头像.jpg");
            } else {
                url = new URL("file:" + msg.getCommunication().getSender().getHeadimage());
            }
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }
        javafx.scene.image.Image image = new javafx.scene.image.Image(String.valueOf(url));
        ImageView imageView = new ImageView(image);
        imageView.setFitHeight(50);
        imageView.setFitWidth(50);
        Circle circle = new Circle();
        circle.setCenterX(25);
        circle.setCenterY(25);
        circle.setRadius(25);
        imageView.setClip(circle);
        javafx.scene.image.Image imgpath = new Image("file:" + msg.getCommunication().getContent());
        ImageView messageBubble = new ImageView(imgpath);
        messageBubble.setFitHeight(35);
        messageBubble.setFitWidth(35);
        messageBubble.setStyle("-fx-background-color: rgb(179,231,244); -fx-background-radius: 8px;");
        HBox.setMargin(messageBubble, new javafx.geometry.Insets(8, 0, 0, 0));

        double[] points;
        points = new double[]{
                0.0, 0.0,
                0.0, 10.0,
                10.0, 5.0
        };
        Polygon triangle = new Polygon(points);
        //设置颜色
        triangle.setFill(Color.rgb(179, 231, 244));
        HBox messageBox = new HBox();
        messageBox.setPrefWidth(585);
        //设置空隙
        messageBox.setPadding(new Insets(10, 5, 10, 5));
        HBox.setMargin(triangle, new Insets(15, 10, 0, 0));
        messageBox.getChildren().addAll(messageBubble, triangle, imageView);
        flowPane.getChildren().add(messageBox);
        messageBox.setAlignment(Pos.TOP_RIGHT);
        //ScrollPane scrollPane = ManageChat.getGroupScrollPaneHashMap(Common.user.getUserid() + msg.getCommunication().getGrouper().getGroupid());
        //让发送消息显示在最底部
        scrollPane.vvalueProperty().addListener(new ChangeListener<Number>() {
            @Override
            public void changed(ObservableValue<? extends Number> observableValue, Number oldValue, Number newValue) {
                //判断滑轮是否在最下面
                if (last) {
                    scrollPane.setVvalue(1.0);
                    last = false;
                }
            }
        });
        scrollPane.setVvalue(1.0);
        last = scrollPane.getVvalue() == 1.0;
        Stage stage = (Stage) h0.getScene().getWindow();
        stage.close();
    }

    public void on1(ActionEvent actionEvent) throws IOException, BrokenBarrierException, InterruptedException {
        Message msg = new Message();
        Communication comm  = new Communication();
        comm.setSender(NowUser.user);
        User friend=new User();
        friend.setId(friendid.getText());
        Message getusermsg=new Message();
        getusermsg.setType("getfriend");
        getusermsg.setUser(friend);
        new ClientConnServer().sendinfo(getusermsg);
        NowUser.cyclicBarrier.reset();
        NowUser.cyclicBarrier.await();
        friend=NowUser.friend;
        comm.setReceiver(friend);
        comm.setContent(h1.getText());
        comm.setSendDateTime(new GetTime().getTime());
        comm.setType(4);
        System.out.println(comm.getSender().getId()+"，"+comm.getReceiver().getId()+","+comm.getContent());
        msg.setType("emoji");
        msg.setCommunication(comm);
        new ClientConnServer().sendinfo(msg);
        NowUser.cyclicBarrier.reset();
        NowUser.cyclicBarrier.await();
        FlowPane flowPane=ManageChat.getMeesagelist(NowUser.user.getId()+msg.getCommunication().getReceiver().getId());
        ScrollPane scrollPane=ManageChat.getScrollPaneHashMap(NowUser.user.getId()+msg.getCommunication().getReceiver().getId());
        // System.out.println(flowPane+"flow");
        VBox.setVgrow(flowPane, Priority.ALWAYS);
        URL url = null;
        try {
            if (msg.getCommunication().getSender().getHeadimage() == null || msg.getCommunication().getSender().getHeadimage().equals("") || msg.getCommunication().getSender().getHeadimage().equals("null")) {
                url = new URL("file:E:untitled\\src\\view\\photo\\默认头像.jpg");
            } else {
                url = new URL("file:" + msg.getCommunication().getSender().getHeadimage());
            }
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }
        javafx.scene.image.Image image = new javafx.scene.image.Image(String.valueOf(url));
        ImageView imageView = new ImageView(image);
        imageView.setFitHeight(50);
        imageView.setFitWidth(50);
        Circle circle = new Circle();
        circle.setCenterX(25);
        circle.setCenterY(25);
        circle.setRadius(25);
        imageView.setClip(circle);
        javafx.scene.image.Image imgpath = new Image("file:" + msg.getCommunication().getContent());
        ImageView messageBubble = new ImageView(imgpath);
        messageBubble.setFitHeight(35);
        messageBubble.setFitWidth(35);
        messageBubble.setStyle("-fx-background-color: rgb(179,231,244); -fx-background-radius: 8px;");
        HBox.setMargin(messageBubble, new javafx.geometry.Insets(8, 0, 0, 0));

        double[] points;
        points = new double[]{
                0.0, 0.0,
                0.0, 10.0,
                10.0, 5.0
        };
        Polygon triangle = new Polygon(points);
        //设置颜色
        triangle.setFill(Color.rgb(179, 231, 244));
        HBox messageBox = new HBox();
        messageBox.setPrefWidth(585);
        //设置空隙
        messageBox.setPadding(new Insets(10, 5, 10, 5));
        HBox.setMargin(triangle, new Insets(15, 10, 0, 0));
        messageBox.getChildren().addAll(messageBubble, triangle, imageView);
        flowPane.getChildren().add(messageBox);
        messageBox.setAlignment(Pos.TOP_RIGHT);
        //ScrollPane scrollPane = ManageChat.getGroupScrollPaneHashMap(Common.user.getUserid() + msg.getCommunication().getGrouper().getGroupid());
        //让发送消息显示在最底部
        scrollPane.vvalueProperty().addListener(new ChangeListener<Number>() {
            @Override
            public void changed(ObservableValue<? extends Number> observableValue, Number oldValue, Number newValue) {
                //判断滑轮是否在最下面
                if (last) {
                    scrollPane.setVvalue(1.0);
                    last = false;
                }
            }
        });
        scrollPane.setVvalue(1.0);
        last = scrollPane.getVvalue() == 1.0;
        Stage stage = (Stage) h1.getScene().getWindow();
        stage.close();
    }

    public void on2(ActionEvent actionEvent) throws IOException, BrokenBarrierException, InterruptedException {
        Message msg = new Message();
        Communication comm  = new Communication();
        comm.setSender(NowUser.user);
        User friend=new User();
        friend.setId(friendid.getText());
        Message getusermsg=new Message();
        getusermsg.setType("getfriend");
        getusermsg.setUser(friend);
        new ClientConnServer().sendinfo(getusermsg);
        NowUser.cyclicBarrier.reset();
        NowUser.cyclicBarrier.await();
        friend=NowUser.friend;
        comm.setReceiver(friend);
        comm.setContent(h2.getText());
        comm.setSendDateTime(new GetTime().getTime());
        comm.setType(4);
        System.out.println(comm.getSender().getId()+"，"+comm.getReceiver().getId()+","+comm.getContent());
        msg.setType("emoji");
        msg.setCommunication(comm);
        new ClientConnServer().sendinfo(msg);
        NowUser.cyclicBarrier.reset();
        NowUser.cyclicBarrier.await();
        FlowPane flowPane=ManageChat.getMeesagelist(NowUser.user.getId()+msg.getCommunication().getReceiver().getId());
        ScrollPane scrollPane=ManageChat.getScrollPaneHashMap(NowUser.user.getId()+msg.getCommunication().getReceiver().getId());
        // System.out.println(flowPane+"flow");
        VBox.setVgrow(flowPane, Priority.ALWAYS);
        URL url = null;
        try {
            if (msg.getCommunication().getSender().getHeadimage() == null || msg.getCommunication().getSender().getHeadimage().equals("") || msg.getCommunication().getSender().getHeadimage().equals("null")) {
                url = new URL("file:E:untitled\\src\\view\\photo\\默认头像.jpg");
            } else {
                url = new URL("file:" + msg.getCommunication().getSender().getHeadimage());
            }
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }
        javafx.scene.image.Image image = new javafx.scene.image.Image(String.valueOf(url));
        ImageView imageView = new ImageView(image);
        imageView.setFitHeight(50);
        imageView.setFitWidth(50);
        Circle circle = new Circle();
        circle.setCenterX(25);
        circle.setCenterY(25);
        circle.setRadius(25);
        imageView.setClip(circle);
        javafx.scene.image.Image imgpath = new Image("file:" + msg.getCommunication().getContent());
        ImageView messageBubble = new ImageView(imgpath);
        messageBubble.setFitHeight(35);
        messageBubble.setFitWidth(35);
        messageBubble.setStyle("-fx-background-color: rgb(179,231,244); -fx-background-radius: 8px;");
        HBox.setMargin(messageBubble, new javafx.geometry.Insets(8, 0, 0, 0));

        double[] points;
        points = new double[]{
                0.0, 0.0,
                0.0, 10.0,
                10.0, 5.0
        };
        Polygon triangle = new Polygon(points);
        //设置颜色
        triangle.setFill(Color.rgb(179, 231, 244));
        HBox messageBox = new HBox();
        messageBox.setPrefWidth(585);
        //设置空隙
        messageBox.setPadding(new Insets(10, 5, 10, 5));
        HBox.setMargin(triangle, new Insets(15, 10, 0, 0));
        messageBox.getChildren().addAll(messageBubble, triangle, imageView);
        flowPane.getChildren().add(messageBox);
        messageBox.setAlignment(Pos.TOP_RIGHT);
        //ScrollPane scrollPane = ManageChat.getGroupScrollPaneHashMap(Common.user.getUserid() + msg.getCommunication().getGrouper().getGroupid());
        //让发送消息显示在最底部
        scrollPane.vvalueProperty().addListener(new ChangeListener<Number>() {
            @Override
            public void changed(ObservableValue<? extends Number> observableValue, Number oldValue, Number newValue) {
                //判断滑轮是否在最下面
                if (last) {
                    scrollPane.setVvalue(1.0);
                    last = false;
                }
            }
        });
        scrollPane.setVvalue(1.0);
        last = scrollPane.getVvalue() == 1.0;
        Stage stage = (Stage) h2.getScene().getWindow();
        stage.close();
    }

    public void on3(ActionEvent actionEvent) throws IOException, BrokenBarrierException, InterruptedException {
        Message msg = new Message();
        Communication comm  = new Communication();
        comm.setSender(NowUser.user);
        User friend=new User();
        friend.setId(friendid.getText());
        Message getusermsg=new Message();
        getusermsg.setType("getfriend");
        getusermsg.setUser(friend);
        new ClientConnServer().sendinfo(getusermsg);
        NowUser.cyclicBarrier.reset();
        NowUser.cyclicBarrier.await();
        friend=NowUser.friend;
        comm.setReceiver(friend);
        comm.setContent(h3.getText());
        comm.setSendDateTime(new GetTime().getTime());
        comm.setType(4);
        System.out.println(comm.getSender().getId()+"，"+comm.getReceiver().getId()+","+comm.getContent());
        msg.setType("emoji");
        msg.setCommunication(comm);
        new ClientConnServer().sendinfo(msg);
        NowUser.cyclicBarrier.reset();
        NowUser.cyclicBarrier.await();
        FlowPane flowPane=ManageChat.getMeesagelist(NowUser.user.getId()+msg.getCommunication().getReceiver().getId());
        ScrollPane scrollPane=ManageChat.getScrollPaneHashMap(NowUser.user.getId()+msg.getCommunication().getReceiver().getId());
        // System.out.println(flowPane+"flow");
        VBox.setVgrow(flowPane, Priority.ALWAYS);
        URL url = null;
        try {
            if (msg.getCommunication().getSender().getHeadimage() == null || msg.getCommunication().getSender().getHeadimage().equals("") || msg.getCommunication().getSender().getHeadimage().equals("null")) {
                url = new URL("file:E:untitled\\src\\view\\photo\\默认头像.jpg");
            } else {
                url = new URL("file:" + msg.getCommunication().getSender().getHeadimage());
            }
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }
        javafx.scene.image.Image image = new javafx.scene.image.Image(String.valueOf(url));
        ImageView imageView = new ImageView(image);
        imageView.setFitHeight(50);
        imageView.setFitWidth(50);
        Circle circle = new Circle();
        circle.setCenterX(25);
        circle.setCenterY(25);
        circle.setRadius(25);
        imageView.setClip(circle);
        javafx.scene.image.Image imgpath = new Image("file:" + msg.getCommunication().getContent());
        ImageView messageBubble = new ImageView(imgpath);
        messageBubble.setFitHeight(35);
        messageBubble.setFitWidth(35);
        messageBubble.setStyle("-fx-background-color: rgb(179,231,244); -fx-background-radius: 8px;");
        HBox.setMargin(messageBubble, new javafx.geometry.Insets(8, 0, 0, 0));

        double[] points;
        points = new double[]{
                0.0, 0.0,
                0.0, 10.0,
                10.0, 5.0
        };
        Polygon triangle = new Polygon(points);
        //设置颜色
        triangle.setFill(Color.rgb(179, 231, 244));
        HBox messageBox = new HBox();
        messageBox.setPrefWidth(585);
        //设置空隙
        messageBox.setPadding(new Insets(10, 5, 10, 5));
        HBox.setMargin(triangle, new Insets(15, 10, 0, 0));
        messageBox.getChildren().addAll(messageBubble, triangle, imageView);
        flowPane.getChildren().add(messageBox);
        messageBox.setAlignment(Pos.TOP_RIGHT);
        //ScrollPane scrollPane = ManageChat.getGroupScrollPaneHashMap(Common.user.getUserid() + msg.getCommunication().getGrouper().getGroupid());
        //让发送消息显示在最底部
        scrollPane.vvalueProperty().addListener(new ChangeListener<Number>() {
            @Override
            public void changed(ObservableValue<? extends Number> observableValue, Number oldValue, Number newValue) {
                //判断滑轮是否在最下面
                if (last) {
                    scrollPane.setVvalue(1.0);
                    last = false;
                }
            }
        });
        scrollPane.setVvalue(1.0);
        last = scrollPane.getVvalue() == 1.0;
        Stage stage = (Stage) h3.getScene().getWindow();
        stage.close();
    }

    public void on4(ActionEvent actionEvent) throws IOException, BrokenBarrierException, InterruptedException {
        Message msg = new Message();
        Communication comm  = new Communication();
        comm.setSender(NowUser.user);
        User friend=new User();
        friend.setId(friendid.getText());
        Message getusermsg=new Message();
        getusermsg.setType("getfriend");
        getusermsg.setUser(friend);
        new ClientConnServer().sendinfo(getusermsg);
        NowUser.cyclicBarrier.reset();
        NowUser.cyclicBarrier.await();
        friend=NowUser.friend;
        comm.setReceiver(friend);
        comm.setContent(h4.getText());
        comm.setSendDateTime(new GetTime().getTime());
        comm.setType(4);
        System.out.println(comm.getSender().getId()+"，"+comm.getReceiver().getId()+","+comm.getContent());
        msg.setType("emoji");
        msg.setCommunication(comm);
        new ClientConnServer().sendinfo(msg);
        NowUser.cyclicBarrier.reset();
        NowUser.cyclicBarrier.await();
        FlowPane flowPane=ManageChat.getMeesagelist(NowUser.user.getId()+msg.getCommunication().getReceiver().getId());
        ScrollPane scrollPane=ManageChat.getScrollPaneHashMap(NowUser.user.getId()+msg.getCommunication().getReceiver().getId());
        // System.out.println(flowPane+"flow");
        VBox.setVgrow(flowPane, Priority.ALWAYS);
        URL url = null;
        try {
            if (msg.getCommunication().getSender().getHeadimage() == null || msg.getCommunication().getSender().getHeadimage().equals("") || msg.getCommunication().getSender().getHeadimage().equals("null")) {
                url = new URL("file:E:untitled\\src\\view\\photo\\默认头像.jpg");
            } else {
                url = new URL("file:" + msg.getCommunication().getSender().getHeadimage());
            }
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }
        javafx.scene.image.Image image = new javafx.scene.image.Image(String.valueOf(url));
        ImageView imageView = new ImageView(image);
        imageView.setFitHeight(50);
        imageView.setFitWidth(50);
        Circle circle = new Circle();
        circle.setCenterX(25);
        circle.setCenterY(25);
        circle.setRadius(25);
        imageView.setClip(circle);
        javafx.scene.image.Image imgpath = new Image("file:" + msg.getCommunication().getContent());
        ImageView messageBubble = new ImageView(imgpath);
        messageBubble.setFitHeight(35);
        messageBubble.setFitWidth(35);
        messageBubble.setStyle("-fx-background-color: rgb(179,231,244); -fx-background-radius: 8px;");
        HBox.setMargin(messageBubble, new javafx.geometry.Insets(8, 0, 0, 0));

        double[] points;
        points = new double[]{
                0.0, 0.0,
                0.0, 10.0,
                10.0, 5.0
        };
        Polygon triangle = new Polygon(points);
        //设置颜色
        triangle.setFill(Color.rgb(179, 231, 244));
        HBox messageBox = new HBox();
        messageBox.setPrefWidth(585);
        //设置空隙
        messageBox.setPadding(new Insets(10, 5, 10, 5));
        HBox.setMargin(triangle, new Insets(15, 10, 0, 0));
        messageBox.getChildren().addAll(messageBubble, triangle, imageView);
        flowPane.getChildren().add(messageBox);
        messageBox.setAlignment(Pos.TOP_RIGHT);
        //ScrollPane scrollPane = ManageChat.getGroupScrollPaneHashMap(Common.user.getUserid() + msg.getCommunication().getGrouper().getGroupid());
        //让发送消息显示在最底部
        scrollPane.vvalueProperty().addListener(new ChangeListener<Number>() {
            @Override
            public void changed(ObservableValue<? extends Number> observableValue, Number oldValue, Number newValue) {
                //判断滑轮是否在最下面
                if (last) {
                    scrollPane.setVvalue(1.0);
                    last = false;
                }
            }
        });
        scrollPane.setVvalue(1.0);
        last = scrollPane.getVvalue() == 1.0;
        Stage stage = (Stage) h4.getScene().getWindow();
        stage.close();
    }

    public void on5(ActionEvent actionEvent) throws IOException, BrokenBarrierException, InterruptedException {
        Message msg = new Message();
        Communication comm  = new Communication();
        comm.setSender(NowUser.user);
        User friend=new User();
        friend.setId(friendid.getText());
        Message getusermsg=new Message();
        getusermsg.setType("getfriend");
        getusermsg.setUser(friend);
        new ClientConnServer().sendinfo(getusermsg);
        NowUser.cyclicBarrier.reset();
        NowUser.cyclicBarrier.await();
        friend=NowUser.friend;
        comm.setReceiver(friend);
        comm.setContent(h5.getText());
        comm.setSendDateTime(new GetTime().getTime());
        comm.setType(4);
        System.out.println(comm.getSender().getId()+"，"+comm.getReceiver().getId()+","+comm.getContent());
        msg.setType("emoji");
        msg.setCommunication(comm);
        new ClientConnServer().sendinfo(msg);
        NowUser.cyclicBarrier.reset();
        NowUser.cyclicBarrier.await();
        FlowPane flowPane=ManageChat.getMeesagelist(NowUser.user.getId()+msg.getCommunication().getReceiver().getId());
        ScrollPane scrollPane=ManageChat.getScrollPaneHashMap(NowUser.user.getId()+msg.getCommunication().getReceiver().getId());
        // System.out.println(flowPane+"flow");
        VBox.setVgrow(flowPane, Priority.ALWAYS);
        URL url = null;
        try {
            if (msg.getCommunication().getSender().getHeadimage() == null || msg.getCommunication().getSender().getHeadimage().equals("") || msg.getCommunication().getSender().getHeadimage().equals("null")) {
                url = new URL("file:E:untitled\\src\\view\\photo\\默认头像.jpg");
            } else {
                url = new URL("file:" + msg.getCommunication().getSender().getHeadimage());
            }
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }
        javafx.scene.image.Image image = new javafx.scene.image.Image(String.valueOf(url));
        ImageView imageView = new ImageView(image);
        imageView.setFitHeight(50);
        imageView.setFitWidth(50);
        Circle circle = new Circle();
        circle.setCenterX(25);
        circle.setCenterY(25);
        circle.setRadius(25);
        imageView.setClip(circle);
        javafx.scene.image.Image imgpath = new Image("file:" + msg.getCommunication().getContent());
        ImageView messageBubble = new ImageView(imgpath);
        messageBubble.setFitHeight(35);
        messageBubble.setFitWidth(35);
        messageBubble.setStyle("-fx-background-color: rgb(179,231,244); -fx-background-radius: 8px;");
        HBox.setMargin(messageBubble, new javafx.geometry.Insets(8, 0, 0, 0));

        double[] points;
        points = new double[]{
                0.0, 0.0,
                0.0, 10.0,
                10.0, 5.0
        };
        Polygon triangle = new Polygon(points);
        //设置颜色
        triangle.setFill(Color.rgb(179, 231, 244));
        HBox messageBox = new HBox();
        messageBox.setPrefWidth(680);
        //设置空隙
        messageBox.setPadding(new Insets(10, 5, 10, 5));
        HBox.setMargin(triangle, new Insets(15, 10, 0, 0));
        messageBox.getChildren().addAll(messageBubble, triangle, imageView);
        flowPane.getChildren().add(messageBox);
        messageBox.setAlignment(Pos.TOP_RIGHT);
        //ScrollPane scrollPane = ManageChat.getGroupScrollPaneHashMap(Common.user.getUserid() + msg.getCommunication().getGrouper().getGroupid());
        //让发送消息显示在最底部
        scrollPane.vvalueProperty().addListener(new ChangeListener<Number>() {
            @Override
            public void changed(ObservableValue<? extends Number> observableValue, Number oldValue, Number newValue) {
                //判断滑轮是否在最下面
                if (last) {
                    scrollPane.setVvalue(1.0);
                    last = false;
                }
            }
        });
        scrollPane.setVvalue(1.0);
        last = scrollPane.getVvalue() == 1.0;
        Stage stage = (Stage) h5.getScene().getWindow();
        stage.close();
    }

    public void on6(ActionEvent actionEvent) throws IOException, BrokenBarrierException, InterruptedException {
        Message msg = new Message();
        Communication comm  = new Communication();
        comm.setSender(NowUser.user);
        User friend=new User();
        friend.setId(friendid.getText());
        Message getusermsg=new Message();
        getusermsg.setType("getfriend");
        getusermsg.setUser(friend);
        new ClientConnServer().sendinfo(getusermsg);
        NowUser.cyclicBarrier.reset();
        NowUser.cyclicBarrier.await();
        friend=NowUser.friend;
        comm.setReceiver(friend);
        comm.setContent(h6.getText());
        comm.setSendDateTime(new GetTime().getTime());
        comm.setType(4);
        System.out.println(comm.getSender().getId()+"，"+comm.getReceiver().getId()+","+comm.getContent());
        msg.setType("emoji");
        msg.setCommunication(comm);
        new ClientConnServer().sendinfo(msg);
        NowUser.cyclicBarrier.reset();
        NowUser.cyclicBarrier.await();
        FlowPane flowPane=ManageChat.getMeesagelist(NowUser.user.getId()+msg.getCommunication().getReceiver().getId());
        ScrollPane scrollPane=ManageChat.getScrollPaneHashMap(NowUser.user.getId()+msg.getCommunication().getReceiver().getId());
        // System.out.println(flowPane+"flow");
        VBox.setVgrow(flowPane, Priority.ALWAYS);
        URL url = null;
        try {
            if (msg.getCommunication().getSender().getHeadimage() == null || msg.getCommunication().getSender().getHeadimage().equals("") || msg.getCommunication().getSender().getHeadimage().equals("null")) {
                url = new URL("file:E:untitled\\src\\view\\photo\\默认头像.jpg");
            } else {
                url = new URL("file:" + msg.getCommunication().getSender().getHeadimage());
            }
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }
        javafx.scene.image.Image image = new javafx.scene.image.Image(String.valueOf(url));
        ImageView imageView = new ImageView(image);
        imageView.setFitHeight(50);
        imageView.setFitWidth(50);
        Circle circle = new Circle();
        circle.setCenterX(25);
        circle.setCenterY(25);
        circle.setRadius(25);
        imageView.setClip(circle);
        javafx.scene.image.Image imgpath = new Image("file:" + msg.getCommunication().getContent());
        ImageView messageBubble = new ImageView(imgpath);
        messageBubble.setFitHeight(35);
        messageBubble.setFitWidth(35);
        messageBubble.setStyle("-fx-background-color: rgb(179,231,244); -fx-background-radius: 8px;");
        HBox.setMargin(messageBubble, new javafx.geometry.Insets(8, 0, 0, 0));

        double[] points;
        points = new double[]{
                0.0, 0.0,
                0.0, 10.0,
                10.0, 5.0
        };
        Polygon triangle = new Polygon(points);
        //设置颜色
        triangle.setFill(Color.rgb(179, 231, 244));
        HBox messageBox = new HBox();
        messageBox.setPrefWidth(585);
        //设置空隙
        messageBox.setPadding(new Insets(10, 5, 10, 5));
        HBox.setMargin(triangle, new Insets(15, 10, 0, 0));
        messageBox.getChildren().addAll(messageBubble, triangle, imageView);
        flowPane.getChildren().add(messageBox);
        messageBox.setAlignment(Pos.TOP_RIGHT);
        //ScrollPane scrollPane = ManageChat.getGroupScrollPaneHashMap(Common.user.getUserid() + msg.getCommunication().getGrouper().getGroupid());
        //让发送消息显示在最底部
        scrollPane.vvalueProperty().addListener(new ChangeListener<Number>() {
            @Override
            public void changed(ObservableValue<? extends Number> observableValue, Number oldValue, Number newValue) {
                //判断滑轮是否在最下面
                if (last) {
                    scrollPane.setVvalue(1.0);
                    last = false;
                }
            }
        });
        scrollPane.setVvalue(1.0);
        last = scrollPane.getVvalue() == 1.0;
        Stage stage = (Stage) h6.getScene().getWindow();
        stage.close();
    }

    public void on7(ActionEvent actionEvent) throws IOException, BrokenBarrierException, InterruptedException {
        Message msg = new Message();
        Communication comm  = new Communication();
        comm.setSender(NowUser.user);
        User friend=new User();
        friend.setId(friendid.getText());
        Message getusermsg=new Message();
        getusermsg.setType("getfriend");
        getusermsg.setUser(friend);
        new ClientConnServer().sendinfo(getusermsg);
        NowUser.cyclicBarrier.reset();
        NowUser.cyclicBarrier.await();
        friend=NowUser.friend;
        comm.setReceiver(friend);
        comm.setContent(h7.getText());
        comm.setSendDateTime(new GetTime().getTime());
        comm.setType(4);
        System.out.println(comm.getSender().getId()+"，"+comm.getReceiver().getId()+","+comm.getContent());
        msg.setType("emoji");
        msg.setCommunication(comm);
        new ClientConnServer().sendinfo(msg);
        NowUser.cyclicBarrier.reset();
        NowUser.cyclicBarrier.await();
        FlowPane flowPane=ManageChat.getMeesagelist(NowUser.user.getId()+msg.getCommunication().getReceiver().getId());
        ScrollPane scrollPane=ManageChat.getScrollPaneHashMap(NowUser.user.getId()+msg.getCommunication().getReceiver().getId());
        // System.out.println(flowPane+"flow");
        VBox.setVgrow(flowPane, Priority.ALWAYS);
        URL url = null;
        try {
            if (msg.getCommunication().getSender().getHeadimage() == null || msg.getCommunication().getSender().getHeadimage().equals("") || msg.getCommunication().getSender().getHeadimage().equals("null")) {
                url = new URL("file:E:untitled\\src\\view\\photo\\默认头像.jpg");
            } else {
                url = new URL("file:" + msg.getCommunication().getSender().getHeadimage());
            }
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }
        javafx.scene.image.Image image = new javafx.scene.image.Image(String.valueOf(url));
        ImageView imageView = new ImageView(image);
        imageView.setFitHeight(50);
        imageView.setFitWidth(50);
        Circle circle = new Circle();
        circle.setCenterX(25);
        circle.setCenterY(25);
        circle.setRadius(25);
        imageView.setClip(circle);
        javafx.scene.image.Image imgpath = new Image("file:" + msg.getCommunication().getContent());
        ImageView messageBubble = new ImageView(imgpath);
        messageBubble.setFitHeight(35);
        messageBubble.setFitWidth(35);
        messageBubble.setStyle("-fx-background-color: rgb(179,231,244); -fx-background-radius: 8px;");
        HBox.setMargin(messageBubble, new javafx.geometry.Insets(8, 0, 0, 0));

        double[] points;
        points = new double[]{
                0.0, 0.0,
                0.0, 10.0,
                10.0, 5.0
        };
        Polygon triangle = new Polygon(points);
        //设置颜色
        triangle.setFill(Color.rgb(179, 231, 244));
        HBox messageBox = new HBox();
        messageBox.setPrefWidth(680);
        //设置空隙
        messageBox.setPadding(new Insets(10, 5, 10, 5));
        HBox.setMargin(triangle, new Insets(15, 10, 0, 0));
        messageBox.getChildren().addAll(messageBubble, triangle, imageView);
        flowPane.getChildren().add(messageBox);
        messageBox.setAlignment(Pos.TOP_RIGHT);
        //ScrollPane scrollPane = ManageChat.getGroupScrollPaneHashMap(Common.user.getUserid() + msg.getCommunication().getGrouper().getGroupid());
        //让发送消息显示在最底部
        scrollPane.vvalueProperty().addListener(new ChangeListener<Number>() {
            @Override
            public void changed(ObservableValue<? extends Number> observableValue, Number oldValue, Number newValue) {
                //判断滑轮是否在最下面
                if (last) {
                    scrollPane.setVvalue(1.0);
                    last = false;
                }
            }
        });
        scrollPane.setVvalue(1.0);
        last = scrollPane.getVvalue() == 1.0;
        Stage stage = (Stage) h7.getScene().getWindow();
        stage.close();
    }

    public void on8(ActionEvent actionEvent) throws IOException, BrokenBarrierException, InterruptedException {
        Message msg = new Message();
        Communication comm  = new Communication();
        comm.setSender(NowUser.user);
        User friend=new User();
        friend.setId(friendid.getText());
        Message getusermsg=new Message();
        getusermsg.setType("getfriend");
        getusermsg.setUser(friend);
        new ClientConnServer().sendinfo(getusermsg);
        NowUser.cyclicBarrier.reset();
        NowUser.cyclicBarrier.await();
        friend=NowUser.friend;
        comm.setReceiver(friend);
        comm.setContent(h8.getText());
        comm.setSendDateTime(new GetTime().getTime());
        comm.setType(4);
        System.out.println(comm.getSender().getId()+"，"+comm.getReceiver().getId()+","+comm.getContent());
        msg.setType("emoji");
        msg.setCommunication(comm);
        new ClientConnServer().sendinfo(msg);
        NowUser.cyclicBarrier.reset();
        NowUser.cyclicBarrier.await();
        FlowPane flowPane=ManageChat.getMeesagelist(NowUser.user.getId()+msg.getCommunication().getReceiver().getId());
        ScrollPane scrollPane=ManageChat.getScrollPaneHashMap(NowUser.user.getId()+msg.getCommunication().getReceiver().getId());
        // System.out.println(flowPane+"flow");
        VBox.setVgrow(flowPane, Priority.ALWAYS);
        URL url = null;
        try {
            if (msg.getCommunication().getSender().getHeadimage() == null || msg.getCommunication().getSender().getHeadimage().equals("") || msg.getCommunication().getSender().getHeadimage().equals("null")) {
                url = new URL("file:E:untitled\\src\\view\\photo\\默认头像.jpg");
            } else {
                url = new URL("file:" + msg.getCommunication().getSender().getHeadimage());
            }
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }
        javafx.scene.image.Image image = new javafx.scene.image.Image(String.valueOf(url));
        ImageView imageView = new ImageView(image);
        imageView.setFitHeight(50);
        imageView.setFitWidth(50);
        Circle circle = new Circle();
        circle.setCenterX(25);
        circle.setCenterY(25);
        circle.setRadius(25);
        imageView.setClip(circle);
        javafx.scene.image.Image imgpath = new Image("file:" + msg.getCommunication().getContent());
        ImageView messageBubble = new ImageView(imgpath);
        messageBubble.setFitHeight(35);
        messageBubble.setFitWidth(35);
        messageBubble.setStyle("-fx-background-color: rgb(179,231,244); -fx-background-radius: 8px;");
        HBox.setMargin(messageBubble, new javafx.geometry.Insets(8, 0, 0, 0));

        double[] points;
        points = new double[]{
                0.0, 0.0,
                0.0, 10.0,
                10.0, 5.0
        };
        Polygon triangle = new Polygon(points);
        //设置颜色
        triangle.setFill(Color.rgb(179, 231, 244));
        HBox messageBox = new HBox();
        messageBox.setPrefWidth(680);
        //设置空隙
        messageBox.setPadding(new Insets(10, 5, 10, 5));
        HBox.setMargin(triangle, new Insets(15, 10, 0, 0));
        messageBox.getChildren().addAll(messageBubble, triangle, imageView);
        flowPane.getChildren().add(messageBox);
        messageBox.setAlignment(Pos.TOP_RIGHT);
        //ScrollPane scrollPane = ManageChat.getGroupScrollPaneHashMap(Common.user.getUserid() + msg.getCommunication().getGrouper().getGroupid());
        //让发送消息显示在最底部
        scrollPane.vvalueProperty().addListener(new ChangeListener<Number>() {
            @Override
            public void changed(ObservableValue<? extends Number> observableValue, Number oldValue, Number newValue) {
                //判断滑轮是否在最下面
                if (last) {
                    scrollPane.setVvalue(1.0);
                    last = false;
                }
            }
        });
        scrollPane.setVvalue(1.0);
        last = scrollPane.getVvalue() == 1.0;
        Stage stage = (Stage) h8.getScene().getWindow();
        stage.close();
    }

    public void on9(ActionEvent actionEvent) throws IOException, BrokenBarrierException, InterruptedException {
        Message msg = new Message();
        Communication comm  = new Communication();
        comm.setSender(NowUser.user);
        User friend=new User();
        friend.setId(friendid.getText());
        Message getusermsg=new Message();
        getusermsg.setType("getfriend");
        getusermsg.setUser(friend);
        new ClientConnServer().sendinfo(getusermsg);
        NowUser.cyclicBarrier.reset();
        NowUser.cyclicBarrier.await();
        friend=NowUser.friend;
        comm.setReceiver(friend);
        comm.setContent(h9.getText());
        comm.setSendDateTime(new GetTime().getTime());
        comm.setType(4);
        System.out.println(comm.getSender().getId()+"，"+comm.getReceiver().getId()+","+comm.getContent());
        msg.setType("emoji");
        msg.setCommunication(comm);
        new ClientConnServer().sendinfo(msg);
        NowUser.cyclicBarrier.reset();
        NowUser.cyclicBarrier.await();
        FlowPane flowPane=ManageChat.getMeesagelist(NowUser.user.getId()+msg.getCommunication().getReceiver().getId());
        ScrollPane scrollPane=ManageChat.getScrollPaneHashMap(NowUser.user.getId()+msg.getCommunication().getReceiver().getId());
        // System.out.println(flowPane+"flow");
        VBox.setVgrow(flowPane, Priority.ALWAYS);
        URL url = null;
        try {
            if (msg.getCommunication().getSender().getHeadimage() == null || msg.getCommunication().getSender().getHeadimage().equals("") || msg.getCommunication().getSender().getHeadimage().equals("null")) {
                url = new URL("file:E:untitled\\src\\view\\photo\\默认头像.jpg");
            } else {
                url = new URL("file:" + msg.getCommunication().getSender().getHeadimage());
            }
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }
        javafx.scene.image.Image image = new javafx.scene.image.Image(String.valueOf(url));
        ImageView imageView = new ImageView(image);
        imageView.setFitHeight(50);
        imageView.setFitWidth(50);
        Circle circle = new Circle();
        circle.setCenterX(25);
        circle.setCenterY(25);
        circle.setRadius(25);
        imageView.setClip(circle);
        javafx.scene.image.Image imgpath = new Image("file:" + msg.getCommunication().getContent());
        ImageView messageBubble = new ImageView(imgpath);
        messageBubble.setFitHeight(35);
        messageBubble.setFitWidth(35);
        messageBubble.setStyle("-fx-background-color: rgb(179,231,244); -fx-background-radius: 8px;");
        HBox.setMargin(messageBubble, new javafx.geometry.Insets(8, 0, 0, 0));

        double[] points;
        points = new double[]{
                0.0, 0.0,
                0.0, 10.0,
                10.0, 5.0
        };
        Polygon triangle = new Polygon(points);
        //设置颜色
        triangle.setFill(Color.rgb(179, 231, 244));
        HBox messageBox = new HBox();
        messageBox.setPrefWidth(680);
        //设置空隙
        messageBox.setPadding(new Insets(10, 5, 10, 5));
        HBox.setMargin(triangle, new Insets(15, 10, 0, 0));
        messageBox.getChildren().addAll(messageBubble, triangle, imageView);
        flowPane.getChildren().add(messageBox);
        messageBox.setAlignment(Pos.TOP_RIGHT);
        //ScrollPane scrollPane = ManageChat.getGroupScrollPaneHashMap(Common.user.getUserid() + msg.getCommunication().getGrouper().getGroupid());
        //让发送消息显示在最底部
        scrollPane.vvalueProperty().addListener(new ChangeListener<Number>() {
            @Override
            public void changed(ObservableValue<? extends Number> observableValue, Number oldValue, Number newValue) {
                //判断滑轮是否在最下面
                if (last) {
                    scrollPane.setVvalue(1.0);
                    last = false;
                }
            }
        });
        scrollPane.setVvalue(1.0);
        last = scrollPane.getVvalue() == 1.0;
        Stage stage = (Stage) h9.getScene().getWindow();
        stage.close();
    }

    public void on10(ActionEvent actionEvent) throws IOException, BrokenBarrierException, InterruptedException {
        Message msg = new Message();
        Communication comm  = new Communication();
        comm.setSender(NowUser.user);
        User friend=new User();
        friend.setId(friendid.getText());
        Message getusermsg=new Message();
        getusermsg.setType("getfriend");
        getusermsg.setUser(friend);
        new ClientConnServer().sendinfo(getusermsg);
        NowUser.cyclicBarrier.reset();
        NowUser.cyclicBarrier.await();
        friend=NowUser.friend;
        comm.setReceiver(friend);
        comm.setContent(h10.getText());
        comm.setSendDateTime(new GetTime().getTime());
        comm.setType(4);
        System.out.println(comm.getSender().getId()+"，"+comm.getReceiver().getId()+","+comm.getContent());
        msg.setType("emoji");
        msg.setCommunication(comm);
        new ClientConnServer().sendinfo(msg);
        NowUser.cyclicBarrier.reset();
        NowUser.cyclicBarrier.await();
        FlowPane flowPane=ManageChat.getMeesagelist(NowUser.user.getId()+msg.getCommunication().getReceiver().getId());
        ScrollPane scrollPane=ManageChat.getScrollPaneHashMap(NowUser.user.getId()+msg.getCommunication().getReceiver().getId());
        // System.out.println(flowPane+"flow");
        VBox.setVgrow(flowPane, Priority.ALWAYS);
        URL url = null;
        try {
            if (msg.getCommunication().getSender().getHeadimage() == null || msg.getCommunication().getSender().getHeadimage().equals("") || msg.getCommunication().getSender().getHeadimage().equals("null")) {
                url = new URL("file:E:untitled\\src\\view\\photo\\默认头像.jpg");
            } else {
                url = new URL("file:" + msg.getCommunication().getSender().getHeadimage());
            }
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }
        javafx.scene.image.Image image = new javafx.scene.image.Image(String.valueOf(url));
        ImageView imageView = new ImageView(image);
        imageView.setFitHeight(50);
        imageView.setFitWidth(50);
        Circle circle = new Circle();
        circle.setCenterX(25);
        circle.setCenterY(25);
        circle.setRadius(25);
        imageView.setClip(circle);
        javafx.scene.image.Image imgpath = new Image("file:" + msg.getCommunication().getContent());
        ImageView messageBubble = new ImageView(imgpath);
        messageBubble.setFitHeight(35);
        messageBubble.setFitWidth(35);
        messageBubble.setStyle("-fx-background-color: rgb(179,231,244); -fx-background-radius: 8px;");
        HBox.setMargin(messageBubble, new javafx.geometry.Insets(8, 0, 0, 0));

        double[] points;
        points = new double[]{
                0.0, 0.0,
                0.0, 10.0,
                10.0, 5.0
        };
        Polygon triangle = new Polygon(points);
        //设置颜色
        triangle.setFill(Color.rgb(179, 231, 244));
        HBox messageBox = new HBox();
        messageBox.setPrefWidth(680);
        //设置空隙
        messageBox.setPadding(new Insets(10, 5, 10, 5));
        HBox.setMargin(triangle, new Insets(15, 10, 0, 0));
        messageBox.getChildren().addAll(messageBubble, triangle, imageView);
        flowPane.getChildren().add(messageBox);
        messageBox.setAlignment(Pos.TOP_RIGHT);
        //ScrollPane scrollPane = ManageChat.getGroupScrollPaneHashMap(Common.user.getUserid() + msg.getCommunication().getGrouper().getGroupid());
        //让发送消息显示在最底部
        scrollPane.vvalueProperty().addListener(new ChangeListener<Number>() {
            @Override
            public void changed(ObservableValue<? extends Number> observableValue, Number oldValue, Number newValue) {
                //判断滑轮是否在最下面
                if (last) {
                    scrollPane.setVvalue(1.0);
                    last = false;
                }
            }
        });
        scrollPane.setVvalue(1.0);
        last = scrollPane.getVvalue() == 1.0;
        Stage stage = (Stage) h10.getScene().getWindow();
        stage.close();
    }

    public void on11(ActionEvent actionEvent) throws IOException, BrokenBarrierException, InterruptedException {
        Message msg = new Message();
        Communication comm  = new Communication();
        comm.setSender(NowUser.user);
        User friend=new User();
        friend.setId(friendid.getText());
        Message getusermsg=new Message();
        getusermsg.setType("getfriend");
        getusermsg.setUser(friend);
        new ClientConnServer().sendinfo(getusermsg);
        NowUser.cyclicBarrier.reset();
        NowUser.cyclicBarrier.await();
        friend=NowUser.friend;
        comm.setReceiver(friend);
        comm.setContent(h11.getText());
        comm.setSendDateTime(new GetTime().getTime());
        comm.setType(4);
        System.out.println(comm.getSender().getId()+"，"+comm.getReceiver().getId()+","+comm.getContent());
        msg.setType("emoji");
        msg.setCommunication(comm);
        new ClientConnServer().sendinfo(msg);
        NowUser.cyclicBarrier.reset();
        NowUser.cyclicBarrier.await();
        FlowPane flowPane=ManageChat.getMeesagelist(NowUser.user.getId()+msg.getCommunication().getReceiver().getId());
        ScrollPane scrollPane=ManageChat.getScrollPaneHashMap(NowUser.user.getId()+msg.getCommunication().getReceiver().getId());
        // System.out.println(flowPane+"flow");
        VBox.setVgrow(flowPane, Priority.ALWAYS);
        URL url = null;
        try {
            if (msg.getCommunication().getSender().getHeadimage() == null || msg.getCommunication().getSender().getHeadimage().equals("") || msg.getCommunication().getSender().getHeadimage().equals("null")) {
                url = new URL("file:E:untitled\\src\\view\\photo\\默认头像.jpg");
            } else {
                url = new URL("file:" + msg.getCommunication().getSender().getHeadimage());
            }
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }
        javafx.scene.image.Image image = new javafx.scene.image.Image(String.valueOf(url));
        ImageView imageView = new ImageView(image);
        imageView.setFitHeight(50);
        imageView.setFitWidth(50);
        Circle circle = new Circle();
        circle.setCenterX(25);
        circle.setCenterY(25);
        circle.setRadius(25);
        imageView.setClip(circle);
        javafx.scene.image.Image imgpath = new Image("file:" + msg.getCommunication().getContent());
        ImageView messageBubble = new ImageView(imgpath);
        messageBubble.setFitHeight(35);
        messageBubble.setFitWidth(35);
        messageBubble.setStyle("-fx-background-color: rgb(179,231,244); -fx-background-radius: 8px;");
        HBox.setMargin(messageBubble, new javafx.geometry.Insets(8, 0, 0, 0));

        double[] points;
        points = new double[]{
                0.0, 0.0,
                0.0, 10.0,
                10.0, 5.0
        };
        Polygon triangle = new Polygon(points);
        //设置颜色
        triangle.setFill(Color.rgb(179, 231, 244));
        HBox messageBox = new HBox();
        messageBox.setPrefWidth(680);
        //设置空隙
        messageBox.setPadding(new Insets(10, 5, 10, 5));
        HBox.setMargin(triangle, new Insets(15, 10, 0, 0));
        messageBox.getChildren().addAll(messageBubble, triangle, imageView);
        flowPane.getChildren().add(messageBox);
        messageBox.setAlignment(Pos.TOP_RIGHT);
        //ScrollPane scrollPane = ManageChat.getGroupScrollPaneHashMap(Common.user.getUserid() + msg.getCommunication().getGrouper().getGroupid());
        //让发送消息显示在最底部
        scrollPane.vvalueProperty().addListener(new ChangeListener<Number>() {
            @Override
            public void changed(ObservableValue<? extends Number> observableValue, Number oldValue, Number newValue) {
                //判断滑轮是否在最下面
                if (last) {
                    scrollPane.setVvalue(1.0);
                    last = false;
                }
            }
        });
        scrollPane.setVvalue(1.0);
        last = scrollPane.getVvalue() == 1.0;
        Stage stage = (Stage) h11.getScene().getWindow();
        stage.close();
    }

    public void on12(ActionEvent actionEvent) throws IOException, BrokenBarrierException, InterruptedException {
        Message msg = new Message();
        Communication comm  = new Communication();
        comm.setSender(NowUser.user);
        User friend=new User();
        friend.setId(friendid.getText());
        Message getusermsg=new Message();
        getusermsg.setType("getfriend");
        getusermsg.setUser(friend);
        new ClientConnServer().sendinfo(getusermsg);
        NowUser.cyclicBarrier.reset();
        NowUser.cyclicBarrier.await();
        friend=NowUser.friend;
        comm.setReceiver(friend);
        comm.setContent(h12.getText());
        comm.setSendDateTime(new GetTime().getTime());
        comm.setType(4);
        System.out.println(comm.getSender().getId()+"，"+comm.getReceiver().getId()+","+comm.getContent());
        msg.setType("emoji");
        msg.setCommunication(comm);
        new ClientConnServer().sendinfo(msg);
        NowUser.cyclicBarrier.reset();
        NowUser.cyclicBarrier.await();
        FlowPane flowPane=ManageChat.getMeesagelist(NowUser.user.getId()+msg.getCommunication().getReceiver().getId());
        ScrollPane scrollPane=ManageChat.getScrollPaneHashMap(NowUser.user.getId()+msg.getCommunication().getReceiver().getId());
        // System.out.println(flowPane+"flow");
        VBox.setVgrow(flowPane, Priority.ALWAYS);
        URL url = null;
        try {
            if (msg.getCommunication().getSender().getHeadimage() == null || msg.getCommunication().getSender().getHeadimage().equals("") || msg.getCommunication().getSender().getHeadimage().equals("null")) {
                url = new URL("file:E:untitled\\src\\view\\photo\\默认头像.jpg");
            } else {
                url = new URL("file:" + msg.getCommunication().getSender().getHeadimage());
            }
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }
        javafx.scene.image.Image image = new javafx.scene.image.Image(String.valueOf(url));
        ImageView imageView = new ImageView(image);
        imageView.setFitHeight(50);
        imageView.setFitWidth(50);
        Circle circle = new Circle();
        circle.setCenterX(25);
        circle.setCenterY(25);
        circle.setRadius(25);
        imageView.setClip(circle);
        javafx.scene.image.Image imgpath = new Image("file:" + msg.getCommunication().getContent());
        ImageView messageBubble = new ImageView(imgpath);
        messageBubble.setFitHeight(35);
        messageBubble.setFitWidth(35);
        messageBubble.setStyle("-fx-background-color: rgb(179,231,244); -fx-background-radius: 8px;");
        HBox.setMargin(messageBubble, new javafx.geometry.Insets(8, 0, 0, 0));

        double[] points;
        points = new double[]{
                0.0, 0.0,
                0.0, 10.0,
                10.0, 5.0
        };
        Polygon triangle = new Polygon(points);
        //设置颜色
        triangle.setFill(Color.rgb(179, 231, 244));
        HBox messageBox = new HBox();
        messageBox.setPrefWidth(680);
        //设置空隙
        messageBox.setPadding(new Insets(10, 5, 10, 5));
        HBox.setMargin(triangle, new Insets(15, 10, 0, 0));
        messageBox.getChildren().addAll(messageBubble, triangle, imageView);
        flowPane.getChildren().add(messageBox);
        messageBox.setAlignment(Pos.TOP_RIGHT);
        //ScrollPane scrollPane = ManageChat.getGroupScrollPaneHashMap(Common.user.getUserid() + msg.getCommunication().getGrouper().getGroupid());
        //让发送消息显示在最底部
        scrollPane.vvalueProperty().addListener(new ChangeListener<Number>() {
            @Override
            public void changed(ObservableValue<? extends Number> observableValue, Number oldValue, Number newValue) {
                //判断滑轮是否在最下面
                if (last) {
                    scrollPane.setVvalue(1.0);
                    last = false;
                }
            }
        });
        scrollPane.setVvalue(1.0);
        last = scrollPane.getVvalue() == 1.0;
        Stage stage = (Stage) h12.getScene().getWindow();
        stage.close();
    }

    public void on13(ActionEvent actionEvent) throws IOException, BrokenBarrierException, InterruptedException {
        Message msg = new Message();
        Communication comm  = new Communication();
        comm.setSender(NowUser.user);
        User friend=new User();
        friend.setId(friendid.getText());
        Message getusermsg=new Message();
        getusermsg.setType("getfriend");
        getusermsg.setUser(friend);
        new ClientConnServer().sendinfo(getusermsg);
        NowUser.cyclicBarrier.reset();
        NowUser.cyclicBarrier.await();
        friend=NowUser.friend;
        comm.setReceiver(friend);
        comm.setContent(h13.getText());
        comm.setSendDateTime(new GetTime().getTime());
        comm.setType(4);
        System.out.println(comm.getSender().getId()+"，"+comm.getReceiver().getId()+","+comm.getContent());
        msg.setType("emoji");
        msg.setCommunication(comm);
        new ClientConnServer().sendinfo(msg);
        NowUser.cyclicBarrier.reset();
        NowUser.cyclicBarrier.await();
        FlowPane flowPane=ManageChat.getMeesagelist(NowUser.user.getId()+msg.getCommunication().getReceiver().getId());
        ScrollPane scrollPane=ManageChat.getScrollPaneHashMap(NowUser.user.getId()+msg.getCommunication().getReceiver().getId());
        // System.out.println(flowPane+"flow");
        VBox.setVgrow(flowPane, Priority.ALWAYS);
        URL url = null;
        try {
            if (msg.getCommunication().getSender().getHeadimage() == null || msg.getCommunication().getSender().getHeadimage().equals("") || msg.getCommunication().getSender().getHeadimage().equals("null")) {
                url = new URL("file:E:untitled\\src\\view\\photo\\默认头像.jpg");
            } else {
                url = new URL("file:" + msg.getCommunication().getSender().getHeadimage());
            }
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }
        javafx.scene.image.Image image = new javafx.scene.image.Image(String.valueOf(url));
        ImageView imageView = new ImageView(image);
        imageView.setFitHeight(50);
        imageView.setFitWidth(50);
        Circle circle = new Circle();
        circle.setCenterX(25);
        circle.setCenterY(25);
        circle.setRadius(25);
        imageView.setClip(circle);
        javafx.scene.image.Image imgpath = new Image("file:" + msg.getCommunication().getContent());
        ImageView messageBubble = new ImageView(imgpath);
        messageBubble.setFitHeight(35);
        messageBubble.setFitWidth(35);
        messageBubble.setStyle("-fx-background-color: rgb(179,231,244); -fx-background-radius: 8px;");
        HBox.setMargin(messageBubble, new javafx.geometry.Insets(8, 0, 0, 0));

        double[] points;
        points = new double[]{
                0.0, 0.0,
                0.0, 10.0,
                10.0, 5.0
        };
        Polygon triangle = new Polygon(points);
        //设置颜色
        triangle.setFill(Color.rgb(179, 231, 244));
        HBox messageBox = new HBox();
        messageBox.setPrefWidth(680);
        //设置空隙
        messageBox.setPadding(new Insets(10, 5, 10, 5));
        HBox.setMargin(triangle, new Insets(15, 10, 0, 0));
        messageBox.getChildren().addAll(messageBubble, triangle, imageView);
        flowPane.getChildren().add(messageBox);
        messageBox.setAlignment(Pos.TOP_RIGHT);
        //ScrollPane scrollPane = ManageChat.getGroupScrollPaneHashMap(Common.user.getUserid() + msg.getCommunication().getGrouper().getGroupid());
        //让发送消息显示在最底部
        scrollPane.vvalueProperty().addListener(new ChangeListener<Number>() {
            @Override
            public void changed(ObservableValue<? extends Number> observableValue, Number oldValue, Number newValue) {
                //判断滑轮是否在最下面
                if (last) {
                    scrollPane.setVvalue(1.0);
                    last = false;
                }
            }
        });
        scrollPane.setVvalue(1.0);
        last = scrollPane.getVvalue() == 1.0;
        Stage stage = (Stage) h13.getScene().getWindow();
        stage.close();
    }

    public void on14(ActionEvent actionEvent) throws IOException, BrokenBarrierException, InterruptedException {
        Message msg = new Message();
        Communication comm  = new Communication();
        comm.setSender(NowUser.user);
        User friend=new User();
        friend.setId(friendid.getText());
        Message getusermsg=new Message();
        getusermsg.setType("getfriend");
        getusermsg.setUser(friend);
        new ClientConnServer().sendinfo(getusermsg);
        NowUser.cyclicBarrier.reset();
        NowUser.cyclicBarrier.await();
        friend=NowUser.friend;
        comm.setReceiver(friend);
        comm.setContent(h14.getText());
        comm.setSendDateTime(new GetTime().getTime());
        comm.setType(4);
        System.out.println(comm.getSender().getId()+"，"+comm.getReceiver().getId()+","+comm.getContent());
        msg.setType("emoji");
        msg.setCommunication(comm);
        new ClientConnServer().sendinfo(msg);
        NowUser.cyclicBarrier.reset();
        NowUser.cyclicBarrier.await();
        FlowPane flowPane=ManageChat.getMeesagelist(NowUser.user.getId()+msg.getCommunication().getReceiver().getId());
        ScrollPane scrollPane=ManageChat.getScrollPaneHashMap(NowUser.user.getId()+msg.getCommunication().getReceiver().getId());
        // System.out.println(flowPane+"flow");
        VBox.setVgrow(flowPane, Priority.ALWAYS);
        URL url = null;
        try {
            if (msg.getCommunication().getSender().getHeadimage() == null || msg.getCommunication().getSender().getHeadimage().equals("") || msg.getCommunication().getSender().getHeadimage().equals("null")) {
                url = new URL("file:E:untitled\\src\\view\\photo\\默认头像.jpg");
            } else {
                url = new URL("file:" + msg.getCommunication().getSender().getHeadimage());
            }
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }
        javafx.scene.image.Image image = new javafx.scene.image.Image(String.valueOf(url));
        ImageView imageView = new ImageView(image);
        imageView.setFitHeight(50);
        imageView.setFitWidth(50);
        Circle circle = new Circle();
        circle.setCenterX(25);
        circle.setCenterY(25);
        circle.setRadius(25);
        imageView.setClip(circle);
        javafx.scene.image.Image imgpath = new Image("file:" + msg.getCommunication().getContent());
        ImageView messageBubble = new ImageView(imgpath);
        messageBubble.setFitHeight(35);
        messageBubble.setFitWidth(35);
        messageBubble.setStyle("-fx-background-color: rgb(179,231,244); -fx-background-radius: 8px;");
        HBox.setMargin(messageBubble, new javafx.geometry.Insets(8, 0, 0, 0));

        double[] points;
        points = new double[]{
                0.0, 0.0,
                0.0, 10.0,
                10.0, 5.0
        };
        Polygon triangle = new Polygon(points);
        //设置颜色
        triangle.setFill(Color.rgb(179, 231, 244));
        HBox messageBox = new HBox();
        messageBox.setPrefWidth(680);
        //设置空隙
        messageBox.setPadding(new Insets(10, 5, 10, 5));
        HBox.setMargin(triangle, new Insets(15, 10, 0, 0));
        messageBox.getChildren().addAll(messageBubble, triangle, imageView);
        flowPane.getChildren().add(messageBox);
        messageBox.setAlignment(Pos.TOP_RIGHT);
        //ScrollPane scrollPane = ManageChat.getGroupScrollPaneHashMap(Common.user.getUserid() + msg.getCommunication().getGrouper().getGroupid());
        //让发送消息显示在最底部
        scrollPane.vvalueProperty().addListener(new ChangeListener<Number>() {
            @Override
            public void changed(ObservableValue<? extends Number> observableValue, Number oldValue, Number newValue) {
                //判断滑轮是否在最下面
                if (last) {
                    scrollPane.setVvalue(1.0);
                    last = false;
                }
            }
        });
        scrollPane.setVvalue(1.0);
        last = scrollPane.getVvalue() == 1.0;
        Stage stage = (Stage) h14.getScene().getWindow();
        stage.close();
    }

    public void on15(ActionEvent actionEvent) throws IOException, BrokenBarrierException, InterruptedException {
        Message msg = new Message();
        Communication comm  = new Communication();
        comm.setSender(NowUser.user);
        User friend=new User();
        friend.setId(friendid.getText());
        Message getusermsg=new Message();
        getusermsg.setType("getfriend");
        getusermsg.setUser(friend);
        new ClientConnServer().sendinfo(getusermsg);
        NowUser.cyclicBarrier.reset();
        NowUser.cyclicBarrier.await();
        friend=NowUser.friend;
        comm.setReceiver(friend);
        comm.setContent(h15.getText());
        comm.setSendDateTime(new GetTime().getTime());
        comm.setType(4);
        System.out.println(comm.getSender().getId()+"，"+comm.getReceiver().getId()+","+comm.getContent());
        msg.setType("emoji");
        msg.setCommunication(comm);
        new ClientConnServer().sendinfo(msg);
        NowUser.cyclicBarrier.reset();
        NowUser.cyclicBarrier.await();
        FlowPane flowPane=ManageChat.getMeesagelist(NowUser.user.getId()+msg.getCommunication().getReceiver().getId());
        ScrollPane scrollPane=ManageChat.getScrollPaneHashMap(NowUser.user.getId()+msg.getCommunication().getReceiver().getId());
        // System.out.println(flowPane+"flow");
        VBox.setVgrow(flowPane, Priority.ALWAYS);
        URL url = null;
        try {
            if (msg.getCommunication().getSender().getHeadimage() == null || msg.getCommunication().getSender().getHeadimage().equals("") || msg.getCommunication().getSender().getHeadimage().equals("null")) {
                url = new URL("file:E:untitled\\src\\view\\photo\\默认头像.jpg");
            } else {
                url = new URL("file:" + msg.getCommunication().getSender().getHeadimage());
            }
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }
        javafx.scene.image.Image image = new javafx.scene.image.Image(String.valueOf(url));
        ImageView imageView = new ImageView(image);
        imageView.setFitHeight(50);
        imageView.setFitWidth(50);
        Circle circle = new Circle();
        circle.setCenterX(25);
        circle.setCenterY(25);
        circle.setRadius(25);
        imageView.setClip(circle);
        javafx.scene.image.Image imgpath = new Image("file:" + msg.getCommunication().getContent());
        ImageView messageBubble = new ImageView(imgpath);
        messageBubble.setFitHeight(35);
        messageBubble.setFitWidth(35);
        messageBubble.setStyle("-fx-background-color: rgb(179,231,244); -fx-background-radius: 8px;");
        HBox.setMargin(messageBubble, new javafx.geometry.Insets(8, 0, 0, 0));

        double[] points;
        points = new double[]{
                0.0, 0.0,
                0.0, 10.0,
                10.0, 5.0
        };
        Polygon triangle = new Polygon(points);
        //设置颜色
        triangle.setFill(Color.rgb(179, 231, 244));
        HBox messageBox = new HBox();
        messageBox.setPrefWidth(680);
        //设置空隙
        messageBox.setPadding(new Insets(10, 5, 10, 5));
        HBox.setMargin(triangle, new Insets(15, 10, 0, 0));
        messageBox.getChildren().addAll(messageBubble, triangle, imageView);
        flowPane.getChildren().add(messageBox);
        messageBox.setAlignment(Pos.TOP_RIGHT);
        //ScrollPane scrollPane = ManageChat.getGroupScrollPaneHashMap(Common.user.getUserid() + msg.getCommunication().getGrouper().getGroupid());
        //让发送消息显示在最底部
        scrollPane.vvalueProperty().addListener(new ChangeListener<Number>() {
            @Override
            public void changed(ObservableValue<? extends Number> observableValue, Number oldValue, Number newValue) {
                //判断滑轮是否在最下面
                if (last) {
                    scrollPane.setVvalue(1.0);
                    last = false;
                }
            }
        });
        scrollPane.setVvalue(1.0);
        last = scrollPane.getVvalue() == 1.0;
        Stage stage = (Stage) h15.getScene().getWindow();
        stage.close();
    }

    public void on16(ActionEvent actionEvent) throws IOException, BrokenBarrierException, InterruptedException {
        Message msg = new Message();
        Communication comm  = new Communication();
        comm.setSender(NowUser.user);
        User friend=new User();
        friend.setId(friendid.getText());
        Message getusermsg=new Message();
        getusermsg.setType("getfriend");
        getusermsg.setUser(friend);
        new ClientConnServer().sendinfo(getusermsg);
        NowUser.cyclicBarrier.reset();
        NowUser.cyclicBarrier.await();
        friend=NowUser.friend;
        comm.setReceiver(friend);
        comm.setContent(h16.getText());
        comm.setSendDateTime(new GetTime().getTime());
        comm.setType(4);
        System.out.println(comm.getSender().getId()+"，"+comm.getReceiver().getId()+","+comm.getContent());
        msg.setType("emoji");
        msg.setCommunication(comm);
        new ClientConnServer().sendinfo(msg);
        NowUser.cyclicBarrier.reset();
        NowUser.cyclicBarrier.await();
        FlowPane flowPane=ManageChat.getMeesagelist(NowUser.user.getId()+msg.getCommunication().getReceiver().getId());
        ScrollPane scrollPane=ManageChat.getScrollPaneHashMap(NowUser.user.getId()+msg.getCommunication().getReceiver().getId());
        // System.out.println(flowPane+"flow");
        VBox.setVgrow(flowPane, Priority.ALWAYS);
        URL url = null;
        try {
            if (msg.getCommunication().getSender().getHeadimage() == null || msg.getCommunication().getSender().getHeadimage().equals("") || msg.getCommunication().getSender().getHeadimage().equals("null")) {
                url = new URL("file:E:untitled\\src\\view\\photo\\默认头像.jpg");
            } else {
                url = new URL("file:" + msg.getCommunication().getSender().getHeadimage());
            }
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }
        javafx.scene.image.Image image = new javafx.scene.image.Image(String.valueOf(url));
        ImageView imageView = new ImageView(image);
        imageView.setFitHeight(50);
        imageView.setFitWidth(50);
        Circle circle = new Circle();
        circle.setCenterX(25);
        circle.setCenterY(25);
        circle.setRadius(25);
        imageView.setClip(circle);
        javafx.scene.image.Image imgpath = new Image("file:" + msg.getCommunication().getContent());
        ImageView messageBubble = new ImageView(imgpath);
        messageBubble.setFitHeight(35);
        messageBubble.setFitWidth(35);
        messageBubble.setStyle("-fx-background-color: rgb(179,231,244); -fx-background-radius: 8px;");
        HBox.setMargin(messageBubble, new javafx.geometry.Insets(8, 0, 0, 0));

        double[] points;
        points = new double[]{
                0.0, 0.0,
                0.0, 10.0,
                10.0, 5.0
        };
        Polygon triangle = new Polygon(points);
        //设置颜色
        triangle.setFill(Color.rgb(179, 231, 244));
        HBox messageBox = new HBox();
        messageBox.setPrefWidth(680);
        //设置空隙
        messageBox.setPadding(new Insets(10, 5, 10, 5));
        HBox.setMargin(triangle, new Insets(15, 10, 0, 0));
        messageBox.getChildren().addAll(messageBubble, triangle, imageView);
        flowPane.getChildren().add(messageBox);
        messageBox.setAlignment(Pos.TOP_RIGHT);
        //ScrollPane scrollPane = ManageChat.getGroupScrollPaneHashMap(Common.user.getUserid() + msg.getCommunication().getGrouper().getGroupid());
        //让发送消息显示在最底部
        scrollPane.vvalueProperty().addListener(new ChangeListener<Number>() {
            @Override
            public void changed(ObservableValue<? extends Number> observableValue, Number oldValue, Number newValue) {
                //判断滑轮是否在最下面
                if (last) {
                    scrollPane.setVvalue(1.0);
                    last = false;
                }
            }
        });
        scrollPane.setVvalue(1.0);
        last = scrollPane.getVvalue() == 1.0;
        Stage stage = (Stage) h16.getScene().getWindow();
        stage.close();
    }

    public void on17(ActionEvent actionEvent) throws IOException, BrokenBarrierException, InterruptedException {
        Message msg = new Message();
        Communication comm  = new Communication();
        comm.setSender(NowUser.user);
        User friend=new User();
        friend.setId(friendid.getText());
        Message getusermsg=new Message();
        getusermsg.setType("getfriend");
        getusermsg.setUser(friend);
        new ClientConnServer().sendinfo(getusermsg);
        NowUser.cyclicBarrier.reset();
        NowUser.cyclicBarrier.await();
        friend=NowUser.friend;
        comm.setReceiver(friend);
        comm.setContent(h17.getText());
        comm.setSendDateTime(new GetTime().getTime());
        comm.setType(4);
        System.out.println(comm.getSender().getId()+"，"+comm.getReceiver().getId()+","+comm.getContent());
        msg.setType("emoji");
        msg.setCommunication(comm);
        new ClientConnServer().sendinfo(msg);
        NowUser.cyclicBarrier.reset();
        NowUser.cyclicBarrier.await();
        FlowPane flowPane=ManageChat.getMeesagelist(NowUser.user.getId()+msg.getCommunication().getReceiver().getId());
        ScrollPane scrollPane=ManageChat.getScrollPaneHashMap(NowUser.user.getId()+msg.getCommunication().getReceiver().getId());
        // System.out.println(flowPane+"flow");
        VBox.setVgrow(flowPane, Priority.ALWAYS);
        URL url = null;
        try {
            if (msg.getCommunication().getSender().getHeadimage() == null || msg.getCommunication().getSender().getHeadimage().equals("") || msg.getCommunication().getSender().getHeadimage().equals("null")) {
                url = new URL("file:E:untitled\\src\\view\\photo\\默认头像.jpg");
            } else {
                url = new URL("file:" + msg.getCommunication().getSender().getHeadimage());
            }
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }
        javafx.scene.image.Image image = new javafx.scene.image.Image(String.valueOf(url));
        ImageView imageView = new ImageView(image);
        imageView.setFitHeight(50);
        imageView.setFitWidth(50);
        Circle circle = new Circle();
        circle.setCenterX(25);
        circle.setCenterY(25);
        circle.setRadius(25);
        imageView.setClip(circle);
        javafx.scene.image.Image imgpath = new Image("file:" + msg.getCommunication().getContent());
        ImageView messageBubble = new ImageView(imgpath);
        messageBubble.setFitHeight(35);
        messageBubble.setFitWidth(35);
        messageBubble.setStyle("-fx-background-color: rgb(179,231,244); -fx-background-radius: 8px;");
        HBox.setMargin(messageBubble, new javafx.geometry.Insets(8, 0, 0, 0));

        double[] points;
        points = new double[]{
                0.0, 0.0,
                0.0, 10.0,
                10.0, 5.0
        };
        Polygon triangle = new Polygon(points);
        //设置颜色
        triangle.setFill(Color.rgb(179, 231, 244));
        HBox messageBox = new HBox();
        messageBox.setPrefWidth(680);
        //设置空隙
        messageBox.setPadding(new Insets(10, 5, 10, 5));
        HBox.setMargin(triangle, new Insets(15, 10, 0, 0));
        messageBox.getChildren().addAll(messageBubble, triangle, imageView);
        flowPane.getChildren().add(messageBox);
        messageBox.setAlignment(Pos.TOP_RIGHT);
        //ScrollPane scrollPane = ManageChat.getGroupScrollPaneHashMap(Common.user.getUserid() + msg.getCommunication().getGrouper().getGroupid());
        //让发送消息显示在最底部
        scrollPane.vvalueProperty().addListener(new ChangeListener<Number>() {
            @Override
            public void changed(ObservableValue<? extends Number> observableValue, Number oldValue, Number newValue) {
                //判断滑轮是否在最下面
                if (last) {
                    scrollPane.setVvalue(1.0);
                    last = false;
                }
            }
        });
        scrollPane.setVvalue(1.0);
        last = scrollPane.getVvalue() == 1.0;
        Stage stage = (Stage) h17.getScene().getWindow();
        stage.close();
    }

    public void on18(ActionEvent actionEvent) throws IOException, BrokenBarrierException, InterruptedException {
        Message msg = new Message();
        Communication comm  = new Communication();
        comm.setSender(NowUser.user);
        User friend=new User();
        friend.setId(friendid.getText());
        Message getusermsg=new Message();
        getusermsg.setType("getfriend");
        getusermsg.setUser(friend);
        new ClientConnServer().sendinfo(getusermsg);
        NowUser.cyclicBarrier.reset();
        NowUser.cyclicBarrier.await();
        friend=NowUser.friend;
        comm.setReceiver(friend);
        comm.setContent(h18.getText());
        comm.setSendDateTime(new GetTime().getTime());
        comm.setType(4);
        System.out.println(comm.getSender().getId()+"，"+comm.getReceiver().getId()+","+comm.getContent());
        msg.setType("emoji");
        msg.setCommunication(comm);
        new ClientConnServer().sendinfo(msg);
        NowUser.cyclicBarrier.reset();
        NowUser.cyclicBarrier.await();
        FlowPane flowPane=ManageChat.getMeesagelist(NowUser.user.getId()+msg.getCommunication().getReceiver().getId());
        ScrollPane scrollPane=ManageChat.getScrollPaneHashMap(NowUser.user.getId()+msg.getCommunication().getReceiver().getId());
        // System.out.println(flowPane+"flow");
        VBox.setVgrow(flowPane, Priority.ALWAYS);
        URL url = null;
        try {
            if (msg.getCommunication().getSender().getHeadimage() == null || msg.getCommunication().getSender().getHeadimage().equals("") || msg.getCommunication().getSender().getHeadimage().equals("null")) {
                url = new URL("file:E:untitled\\src\\view\\photo\\默认头像.jpg");
            } else {
                url = new URL("file:" + msg.getCommunication().getSender().getHeadimage());
            }
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }
        javafx.scene.image.Image image = new javafx.scene.image.Image(String.valueOf(url));
        ImageView imageView = new ImageView(image);
        imageView.setFitHeight(50);
        imageView.setFitWidth(50);
        Circle circle = new Circle();
        circle.setCenterX(25);
        circle.setCenterY(25);
        circle.setRadius(25);
        imageView.setClip(circle);
        javafx.scene.image.Image imgpath = new Image("file:" + msg.getCommunication().getContent());
        ImageView messageBubble = new ImageView(imgpath);
        messageBubble.setFitHeight(35);
        messageBubble.setFitWidth(35);
        messageBubble.setStyle("-fx-background-color: rgb(179,231,244); -fx-background-radius: 8px;");
        HBox.setMargin(messageBubble, new javafx.geometry.Insets(8, 0, 0, 0));

        double[] points;
        points = new double[]{
                0.0, 0.0,
                0.0, 10.0,
                10.0, 5.0
        };
        Polygon triangle = new Polygon(points);
        //设置颜色
        triangle.setFill(Color.rgb(179, 231, 244));
        HBox messageBox = new HBox();
        messageBox.setPrefWidth(680);
        //设置空隙
        messageBox.setPadding(new Insets(10, 5, 10, 5));
        HBox.setMargin(triangle, new Insets(15, 10, 0, 0));
        messageBox.getChildren().addAll(messageBubble, triangle, imageView);
        flowPane.getChildren().add(messageBox);
        messageBox.setAlignment(Pos.TOP_RIGHT);
        //ScrollPane scrollPane = ManageChat.getGroupScrollPaneHashMap(Common.user.getUserid() + msg.getCommunication().getGrouper().getGroupid());
        //让发送消息显示在最底部
        scrollPane.vvalueProperty().addListener(new ChangeListener<Number>() {
            @Override
            public void changed(ObservableValue<? extends Number> observableValue, Number oldValue, Number newValue) {
                //判断滑轮是否在最下面
                if (last) {
                    scrollPane.setVvalue(1.0);
                    last = false;
                }
            }
        });
        scrollPane.setVvalue(1.0);
        last = scrollPane.getVvalue() == 1.0;
        Stage stage = (Stage) h18.getScene().getWindow();
        stage.close();
    }

    public void on19(ActionEvent actionEvent) throws IOException, BrokenBarrierException, InterruptedException {
        Message msg = new Message();
        Communication comm  = new Communication();
        comm.setSender(NowUser.user);
        User friend=new User();
        friend.setId(friendid.getText());
        Message getusermsg=new Message();
        getusermsg.setType("getfriend");
        getusermsg.setUser(friend);
        new ClientConnServer().sendinfo(getusermsg);
        NowUser.cyclicBarrier.reset();
        NowUser.cyclicBarrier.await();
        friend=NowUser.friend;
        comm.setReceiver(friend);
        comm.setContent(h19.getText());
        comm.setSendDateTime(new GetTime().getTime());
        comm.setType(4);
        System.out.println(comm.getSender().getId()+"，"+comm.getReceiver().getId()+","+comm.getContent());
        msg.setType("emoji");
        msg.setCommunication(comm);
        new ClientConnServer().sendinfo(msg);
        NowUser.cyclicBarrier.reset();
        NowUser.cyclicBarrier.await();
        FlowPane flowPane=ManageChat.getMeesagelist(NowUser.user.getId()+msg.getCommunication().getReceiver().getId());
        ScrollPane scrollPane=ManageChat.getScrollPaneHashMap(NowUser.user.getId()+msg.getCommunication().getReceiver().getId());
        // System.out.println(flowPane+"flow");
        VBox.setVgrow(flowPane, Priority.ALWAYS);
        URL url = null;
        try {
            if (msg.getCommunication().getSender().getHeadimage() == null || msg.getCommunication().getSender().getHeadimage().equals("") || msg.getCommunication().getSender().getHeadimage().equals("null")) {
                url = new URL("file:E:untitled\\src\\view\\photo\\默认头像.jpg");
            } else {
                url = new URL("file:" + msg.getCommunication().getSender().getHeadimage());
            }
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }
        javafx.scene.image.Image image = new javafx.scene.image.Image(String.valueOf(url));
        ImageView imageView = new ImageView(image);
        imageView.setFitHeight(50);
        imageView.setFitWidth(50);
        Circle circle = new Circle();
        circle.setCenterX(25);
        circle.setCenterY(25);
        circle.setRadius(25);
        imageView.setClip(circle);
        javafx.scene.image.Image imgpath = new Image("file:" + msg.getCommunication().getContent());
        ImageView messageBubble = new ImageView(imgpath);
        messageBubble.setFitHeight(35);
        messageBubble.setFitWidth(35);
        messageBubble.setStyle("-fx-background-color: rgb(179,231,244); -fx-background-radius: 8px;");
        HBox.setMargin(messageBubble, new javafx.geometry.Insets(8, 0, 0, 0));

        double[] points;
        points = new double[]{
                0.0, 0.0,
                0.0, 10.0,
                10.0, 5.0
        };
        Polygon triangle = new Polygon(points);
        //设置颜色
        triangle.setFill(Color.rgb(179, 231, 244));
        HBox messageBox = new HBox();
        messageBox.setPrefWidth(680);
        //设置空隙
        messageBox.setPadding(new Insets(10, 5, 10, 5));
        HBox.setMargin(triangle, new Insets(15, 10, 0, 0));
        messageBox.getChildren().addAll(messageBubble, triangle, imageView);
        flowPane.getChildren().add(messageBox);
        messageBox.setAlignment(Pos.TOP_RIGHT);
        //ScrollPane scrollPane = ManageChat.getGroupScrollPaneHashMap(Common.user.getUserid() + msg.getCommunication().getGrouper().getGroupid());
        //让发送消息显示在最底部
        scrollPane.vvalueProperty().addListener(new ChangeListener<Number>() {
            @Override
            public void changed(ObservableValue<? extends Number> observableValue, Number oldValue, Number newValue) {
                //判断滑轮是否在最下面
                if (last) {
                    scrollPane.setVvalue(1.0);
                    last = false;
                }
            }
        });
        scrollPane.setVvalue(1.0);
        last = scrollPane.getVvalue() == 1.0;
        Stage stage = (Stage) h19.getScene().getWindow();
        stage.close();
    }

    public void on20(ActionEvent actionEvent) throws IOException, BrokenBarrierException, InterruptedException {
        Message msg = new Message();
        Communication comm  = new Communication();
        comm.setSender(NowUser.user);
        User friend=new User();
        friend.setId(friendid.getText());
        Message getusermsg=new Message();
        getusermsg.setType("getfriend");
        getusermsg.setUser(friend);
        new ClientConnServer().sendinfo(getusermsg);
        NowUser.cyclicBarrier.reset();
        NowUser.cyclicBarrier.await();
        friend=NowUser.friend;
        comm.setReceiver(friend);
        comm.setContent(h20.getText());
        comm.setSendDateTime(new GetTime().getTime());
        comm.setType(4);
        System.out.println(comm.getSender().getId()+"，"+comm.getReceiver().getId()+","+comm.getContent());
        msg.setType("emoji");
        msg.setCommunication(comm);
        new ClientConnServer().sendinfo(msg);
        NowUser.cyclicBarrier.reset();
        NowUser.cyclicBarrier.await();
        FlowPane flowPane=ManageChat.getMeesagelist(NowUser.user.getId()+msg.getCommunication().getReceiver().getId());
        ScrollPane scrollPane=ManageChat.getScrollPaneHashMap(NowUser.user.getId()+msg.getCommunication().getReceiver().getId());
        // System.out.println(flowPane+"flow");
        VBox.setVgrow(flowPane, Priority.ALWAYS);
        URL url = null;
        try {
            if (msg.getCommunication().getSender().getHeadimage() == null || msg.getCommunication().getSender().getHeadimage().equals("") || msg.getCommunication().getSender().getHeadimage().equals("null")) {
                url = new URL("file:E:untitled\\src\\view\\photo\\默认头像.jpg");
            } else {
                url = new URL("file:" + msg.getCommunication().getSender().getHeadimage());
            }
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }
        javafx.scene.image.Image image = new javafx.scene.image.Image(String.valueOf(url));
        ImageView imageView = new ImageView(image);
        imageView.setFitHeight(50);
        imageView.setFitWidth(50);
        Circle circle = new Circle();
        circle.setCenterX(25);
        circle.setCenterY(25);
        circle.setRadius(25);
        imageView.setClip(circle);
        javafx.scene.image.Image imgpath = new Image("file:" + msg.getCommunication().getContent());
        ImageView messageBubble = new ImageView(imgpath);
        messageBubble.setFitHeight(35);
        messageBubble.setFitWidth(35);
        messageBubble.setStyle("-fx-background-color: rgb(179,231,244); -fx-background-radius: 8px;");
        HBox.setMargin(messageBubble, new javafx.geometry.Insets(8, 0, 0, 0));

        double[] points;
        points = new double[]{
                0.0, 0.0,
                0.0, 10.0,
                10.0, 5.0
        };
        Polygon triangle = new Polygon(points);
        //设置颜色
        triangle.setFill(Color.rgb(179, 231, 244));
        HBox messageBox = new HBox();
        messageBox.setPrefWidth(680);
        //设置空隙
        messageBox.setPadding(new Insets(10, 5, 10, 5));
        HBox.setMargin(triangle, new Insets(15, 10, 0, 0));
        messageBox.getChildren().addAll(messageBubble, triangle, imageView);
        flowPane.getChildren().add(messageBox);
        messageBox.setAlignment(Pos.TOP_RIGHT);
        //ScrollPane scrollPane = ManageChat.getGroupScrollPaneHashMap(Common.user.getUserid() + msg.getCommunication().getGrouper().getGroupid());
        //让发送消息显示在最底部
        scrollPane.vvalueProperty().addListener(new ChangeListener<Number>() {
            @Override
            public void changed(ObservableValue<? extends Number> observableValue, Number oldValue, Number newValue) {
                //判断滑轮是否在最下面
                if (last) {
                    scrollPane.setVvalue(1.0);
                    last = false;
                }
            }
        });
        scrollPane.setVvalue(1.0);
        last = scrollPane.getVvalue() == 1.0;
        Stage stage = (Stage) h20.getScene().getWindow();
        stage.close();
    }

    public void on21(ActionEvent actionEvent) throws IOException, BrokenBarrierException, InterruptedException {
        Message msg = new Message();
        Communication comm  = new Communication();
        comm.setSender(NowUser.user);
        User friend=new User();
        friend.setId(friendid.getText());
        Message getusermsg=new Message();
        getusermsg.setType("getfriend");
        getusermsg.setUser(friend);
        new ClientConnServer().sendinfo(getusermsg);
        NowUser.cyclicBarrier.reset();
        NowUser.cyclicBarrier.await();
        friend=NowUser.friend;
        comm.setReceiver(friend);
        comm.setContent(h21.getText());
        comm.setSendDateTime(new GetTime().getTime());
        comm.setType(4);
        System.out.println(comm.getSender().getId()+"，"+comm.getReceiver().getId()+","+comm.getContent());
        msg.setType("emoji");
        msg.setCommunication(comm);
        new ClientConnServer().sendinfo(msg);
        NowUser.cyclicBarrier.reset();
        NowUser.cyclicBarrier.await();
        FlowPane flowPane=ManageChat.getMeesagelist(NowUser.user.getId()+msg.getCommunication().getReceiver().getId());
        ScrollPane scrollPane=ManageChat.getScrollPaneHashMap(NowUser.user.getId()+msg.getCommunication().getReceiver().getId());
        // System.out.println(flowPane+"flow");
        VBox.setVgrow(flowPane, Priority.ALWAYS);
        URL url = null;
        try {
            if (msg.getCommunication().getSender().getHeadimage() == null || msg.getCommunication().getSender().getHeadimage().equals("") || msg.getCommunication().getSender().getHeadimage().equals("null")) {
                url = new URL("file:E:untitled\\src\\view\\photo\\默认头像.jpg");
            } else {
                url = new URL("file:" + msg.getCommunication().getSender().getHeadimage());
            }
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }
        javafx.scene.image.Image image = new javafx.scene.image.Image(String.valueOf(url));
        ImageView imageView = new ImageView(image);
        imageView.setFitHeight(50);
        imageView.setFitWidth(50);
        Circle circle = new Circle();
        circle.setCenterX(25);
        circle.setCenterY(25);
        circle.setRadius(25);
        imageView.setClip(circle);
        javafx.scene.image.Image imgpath = new Image("file:" + msg.getCommunication().getContent());
        ImageView messageBubble = new ImageView(imgpath);
        messageBubble.setFitHeight(35);
        messageBubble.setFitWidth(35);
        messageBubble.setStyle("-fx-background-color: rgb(179,231,244); -fx-background-radius: 8px;");
        HBox.setMargin(messageBubble, new javafx.geometry.Insets(8, 0, 0, 0));

        double[] points;
        points = new double[]{
                0.0, 0.0,
                0.0, 10.0,
                10.0, 5.0
        };
        Polygon triangle = new Polygon(points);
        //设置颜色
        triangle.setFill(Color.rgb(179, 231, 244));
        HBox messageBox = new HBox();
        messageBox.setPrefWidth(680);
        //设置空隙
        messageBox.setPadding(new Insets(10, 5, 10, 5));
        HBox.setMargin(triangle, new Insets(15, 10, 0, 0));
        messageBox.getChildren().addAll(messageBubble, triangle, imageView);
        flowPane.getChildren().add(messageBox);
        messageBox.setAlignment(Pos.TOP_RIGHT);
        //ScrollPane scrollPane = ManageChat.getGroupScrollPaneHashMap(Common.user.getUserid() + msg.getCommunication().getGrouper().getGroupid());
        //让发送消息显示在最底部
        scrollPane.vvalueProperty().addListener(new ChangeListener<Number>() {
            @Override
            public void changed(ObservableValue<? extends Number> observableValue, Number oldValue, Number newValue) {
                //判断滑轮是否在最下面
                if (last) {
                    scrollPane.setVvalue(1.0);
                    last = false;
                }
            }
        });
        scrollPane.setVvalue(1.0);
        last = scrollPane.getVvalue() == 1.0;
        Stage stage = (Stage) h21.getScene().getWindow();
        stage.close();
    }

    public void on22(ActionEvent actionEvent) throws IOException, BrokenBarrierException, InterruptedException {
        Message msg = new Message();
        Communication comm  = new Communication();
        comm.setSender(NowUser.user);
        User friend=new User();
        friend.setId(friendid.getText());
        Message getusermsg=new Message();
        getusermsg.setType("getfriend");
        getusermsg.setUser(friend);
        new ClientConnServer().sendinfo(getusermsg);
        NowUser.cyclicBarrier.reset();
        NowUser.cyclicBarrier.await();
        friend=NowUser.friend;
        comm.setReceiver(friend);
        comm.setContent(h22.getText());
        comm.setSendDateTime(new GetTime().getTime());
        comm.setType(4);
        System.out.println(comm.getSender().getId()+"，"+comm.getReceiver().getId()+","+comm.getContent());
        msg.setType("emoji");
        msg.setCommunication(comm);
        new ClientConnServer().sendinfo(msg);
        NowUser.cyclicBarrier.reset();
        NowUser.cyclicBarrier.await();
        FlowPane flowPane=ManageChat.getMeesagelist(NowUser.user.getId()+msg.getCommunication().getReceiver().getId());
        ScrollPane scrollPane=ManageChat.getScrollPaneHashMap(NowUser.user.getId()+msg.getCommunication().getReceiver().getId());
        // System.out.println(flowPane+"flow");
        VBox.setVgrow(flowPane, Priority.ALWAYS);
        URL url = null;
        try {
            if (msg.getCommunication().getSender().getHeadimage() == null || msg.getCommunication().getSender().getHeadimage().equals("") || msg.getCommunication().getSender().getHeadimage().equals("null")) {
                url = new URL("file:E:untitled\\src\\view\\photo\\默认头像.jpg");
            } else {
                url = new URL("file:" + msg.getCommunication().getSender().getHeadimage());
            }
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }
        javafx.scene.image.Image image = new javafx.scene.image.Image(String.valueOf(url));
        ImageView imageView = new ImageView(image);
        imageView.setFitHeight(50);
        imageView.setFitWidth(50);
        Circle circle = new Circle();
        circle.setCenterX(25);
        circle.setCenterY(25);
        circle.setRadius(25);
        imageView.setClip(circle);
        javafx.scene.image.Image imgpath = new Image("file:" + msg.getCommunication().getContent());
        ImageView messageBubble = new ImageView(imgpath);
        messageBubble.setFitHeight(35);
        messageBubble.setFitWidth(35);
        messageBubble.setStyle("-fx-background-color: rgb(179,231,244); -fx-background-radius: 8px;");
        HBox.setMargin(messageBubble, new javafx.geometry.Insets(8, 0, 0, 0));

        double[] points;
        points = new double[]{
                0.0, 0.0,
                0.0, 10.0,
                10.0, 5.0
        };
        Polygon triangle = new Polygon(points);
        //设置颜色
        triangle.setFill(Color.rgb(179, 231, 244));
        HBox messageBox = new HBox();
        messageBox.setPrefWidth(680);
        //设置空隙
        messageBox.setPadding(new Insets(10, 5, 10, 5));
        HBox.setMargin(triangle, new Insets(15, 10, 0, 0));
        messageBox.getChildren().addAll(messageBubble, triangle, imageView);
        flowPane.getChildren().add(messageBox);
        messageBox.setAlignment(Pos.TOP_RIGHT);
        //ScrollPane scrollPane = ManageChat.getGroupScrollPaneHashMap(Common.user.getUserid() + msg.getCommunication().getGrouper().getGroupid());
        //让发送消息显示在最底部
        scrollPane.vvalueProperty().addListener(new ChangeListener<Number>() {
            @Override
            public void changed(ObservableValue<? extends Number> observableValue, Number oldValue, Number newValue) {
                //判断滑轮是否在最下面
                if (last) {
                    scrollPane.setVvalue(1.0);
                    last = false;
                }
            }
        });
        scrollPane.setVvalue(1.0);
        last = scrollPane.getVvalue() == 1.0;
        Stage stage = (Stage) h22.getScene().getWindow();
        stage.close();
    }

    public void on23(ActionEvent actionEvent) throws IOException, BrokenBarrierException, InterruptedException {
        Message msg = new Message();
        Communication comm  = new Communication();
        comm.setSender(NowUser.user);
        User friend=new User();
        friend.setId(friendid.getText());
        Message getusermsg=new Message();
        getusermsg.setType("getfriend");
        getusermsg.setUser(friend);
        new ClientConnServer().sendinfo(getusermsg);
        NowUser.cyclicBarrier.reset();
        NowUser.cyclicBarrier.await();
        friend=NowUser.friend;
        comm.setReceiver(friend);
        comm.setContent(h23.getText());
        comm.setSendDateTime(new GetTime().getTime());
        comm.setType(4);
        System.out.println(comm.getSender().getId()+"，"+comm.getReceiver().getId()+","+comm.getContent());
        msg.setType("emoji");
        msg.setCommunication(comm);
        new ClientConnServer().sendinfo(msg);
        NowUser.cyclicBarrier.reset();
        NowUser.cyclicBarrier.await();
        FlowPane flowPane=ManageChat.getMeesagelist(NowUser.user.getId()+msg.getCommunication().getReceiver().getId());
        ScrollPane scrollPane=ManageChat.getScrollPaneHashMap(NowUser.user.getId()+msg.getCommunication().getReceiver().getId());
        // System.out.println(flowPane+"flow");
        VBox.setVgrow(flowPane, Priority.ALWAYS);
        URL url = null;
        try {
            if (msg.getCommunication().getSender().getHeadimage() == null || msg.getCommunication().getSender().getHeadimage().equals("") || msg.getCommunication().getSender().getHeadimage().equals("null")) {
                url = new URL("file:E:untitled\\src\\view\\photo\\默认头像.jpg");
            } else {
                url = new URL("file:" + msg.getCommunication().getSender().getHeadimage());
            }
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }
        javafx.scene.image.Image image = new javafx.scene.image.Image(String.valueOf(url));
        ImageView imageView = new ImageView(image);
        imageView.setFitHeight(50);
        imageView.setFitWidth(50);
        Circle circle = new Circle();
        circle.setCenterX(25);
        circle.setCenterY(25);
        circle.setRadius(25);
        imageView.setClip(circle);
        javafx.scene.image.Image imgpath = new Image("file:" + msg.getCommunication().getContent());
        ImageView messageBubble = new ImageView(imgpath);
        messageBubble.setFitHeight(35);
        messageBubble.setFitWidth(35);
        messageBubble.setStyle("-fx-background-color: rgb(179,231,244); -fx-background-radius: 8px;");
        HBox.setMargin(messageBubble, new javafx.geometry.Insets(8, 0, 0, 0));

        double[] points;
        points = new double[]{
                0.0, 0.0,
                0.0, 10.0,
                10.0, 5.0
        };
        Polygon triangle = new Polygon(points);
        //设置颜色
        triangle.setFill(Color.rgb(179, 231, 244));
        HBox messageBox = new HBox();
        messageBox.setPrefWidth(680);
        //设置空隙
        messageBox.setPadding(new Insets(10, 5, 10, 5));
        HBox.setMargin(triangle, new Insets(15, 10, 0, 0));
        messageBox.getChildren().addAll(messageBubble, triangle, imageView);
        flowPane.getChildren().add(messageBox);
        messageBox.setAlignment(Pos.TOP_RIGHT);
        //ScrollPane scrollPane = ManageChat.getGroupScrollPaneHashMap(Common.user.getUserid() + msg.getCommunication().getGrouper().getGroupid());
        //让发送消息显示在最底部
        scrollPane.vvalueProperty().addListener(new ChangeListener<Number>() {
            @Override
            public void changed(ObservableValue<? extends Number> observableValue, Number oldValue, Number newValue) {
                //判断滑轮是否在最下面
                if (last) {
                    scrollPane.setVvalue(1.0);
                    last = false;
                }
            }
        });
        scrollPane.setVvalue(1.0);
        last = scrollPane.getVvalue() == 1.0;
        Stage stage = (Stage) h23.getScene().getWindow();
        stage.close();
    }
}
